<?php

namespace app\api\validate;

use think\Validate;

class User extends Validate
{
    /**
     * 验证规则
     */
    protected $rule = [
        'nickname' => 'require',
        'password' => 'regex:\S{6,32}',
        'pay_password' => 'regex:\S{6}',
        'username' => 'require|unique:user|max:11|/^1[3-8]{1}[0-9]{9}$/',
        'invitation_code' => 'require',

    ];

    /**
     * 字段描述
     */
    protected $field = [
    ];
    /**
     * 提示消息
     */
    protected $message = [
        'nickname.require' => '请输入昵称',
        'username.require' => '请输入手机号',
        'username.unique:user' => '手机号已被注册',
        'username.max' => '手机号码不能超过11位',
        'username./^1[3-8]{1}[0-9]{9}$/' => '手机号码格式不正确',
        'invitation_code.require' => '请输入邀请码',
        'password.regex:\S{6,32}' => '密码6-32位',
        'pay_password.regex:\S{6}' => '支付密码6位'
    ];
    /**
     * 验证场景
     */
    protected $scene = [
        'add' => [],
        'edit' => ['username', 'nickname', 'password', 'email', 'mobile'],
        'register' => ['nickname', 'password', 'pay_password', 'username', 'invitation_code'],
    ];

    public function __construct(array $rules = [], $message = [], $field = [])
    {
        $this->field = [
            'username' => __('Username'),
            'nickname' => __('Nickname'),
            'password' => __('Password'),
            'email' => __('Email'),
            'mobile' => __('Mobile')
        ];
        parent::__construct($rules, $message, $field);
    }

}
